﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Raven.Imports.Newtonsoft.Json;
using SampleApp.MvcBackend.ComponentModel;

namespace SampleApp.MvcBackend.Data.Model
{
	public class Customer : Aggregate
	{
		DateTimeOffset CreatedOn { get; set; }
		String CustomerName { get; set; }

		[JsonConstructor]
		private Customer()
		{

		}

		Customer SetupCompleted()
		{
			this.RaiseEvent( new CustomerCreated( this.Id, this.CustomerName) );

			return this;
		}

		public class Factory
		{
			public Factory()
			{
				
			}

			public Customer CreateNew(String customerName)
			{
				return new Customer()
				{
					Id = String.Format( "customers/{0}", Guid.NewGuid() ),
					CustomerName = customerName,
					CreatedOn = DateTimeOffset.Now
				}.SetupCompleted();
			}
		}
	}
}